package com.power.algorithm;

import java.util.Arrays;

/**
 * @description:
 * @author: jiangnan
 * @time: 2021/6/17 4:21 下午
 */
public class Solution283 {
    public void moveZeroes(int[] nums) {
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                //如果是0 索引不动
                continue;
            } else {
                //如果不是0 索引覆盖之前的
                nums[index++] = nums[i];
            }
        }


        for (int j = index; j < nums.length; j++) {
            nums[j] = 0;
        }
        System.out.println(Arrays.toString(nums));
    }

    public static void main(String[] args) {
        int[] nums = {0, 2, 3, 4, 4, 5, 0, 6, 7, 0, 8, 9, 0};
        Solution283 solution283 = new Solution283();
        solution283.moveZeroes(nums);
    }
}
